package com.tedu.openmedical.medicalsystem.sysDictDetail.service.impl;

import com.tedu.openmedical.medicalsystem.sysDictDetail.mapper.SysDictDataDetailMapper;
import com.tedu.openmedical.medicalsystem.sysDictDetail.pojo.VO.SysDictDetailDataVO;
import com.tedu.openmedical.medicalsystem.sysDictDetail.pojo.dto.DictDetailQuery;
import com.tedu.openmedical.medicalsystem.sysDictDetail.pojo.dto.DictDetailSaveParam;
import com.tedu.openmedical.medicalsystem.sysDictDetail.pojo.entity.SysDictDetailData;
import com.tedu.openmedical.medicalsystem.sysDictDetail.service.SysDictDataDetailService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
public class SysDictDataDetailServiceImpl implements SysDictDataDetailService {

    @Autowired
    private SysDictDataDetailMapper sysDictDataDetailMapper;

    @Override
    public List<SysDictDetailDataVO> selectDictDetailList(DictDetailQuery dictDetailQuery) {
        List<SysDictDetailDataVO> result = sysDictDataDetailMapper.selectDictDetailList(dictDetailQuery);
        if (result == null) {
            result = Collections.emptyList();
        }
        return result;
    }

    @Override
    public void save(DictDetailSaveParam dictDetailSaveParam) {
        SysDictDetailData sysDictDetailData = new SysDictDetailData();
        BeanUtils.copyProperties(dictDetailSaveParam, sysDictDetailData);
        if (sysDictDetailData.getId() == null){
            sysDictDetailData.setCreateTime(new Date());
            sysDictDetailData.setUpdateTime(new Date());
            sysDictDetailData.setCreateBy(dictDetailSaveParam.getCreateBy());
            sysDictDataDetailMapper.insert(sysDictDetailData);
        } else {
            sysDictDetailData.setUpdateTime(new Date());
            sysDictDetailData.setUpdateBy(dictDetailSaveParam.getUpdateBy());
            sysDictDataDetailMapper.update(sysDictDetailData);
        }

    }

    @Override
    public void deleteDictDetail(Long id) {
        sysDictDataDetailMapper.deleteDictDetail(id);
    }
}
